package com.qf.logistics.security.handler;

import com.qf.logistics.mapper.RoleMapper;
import com.qf.logistics.pojo.SysRole;
import com.qf.logistics.security.service.BaseUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * created by 赵文韬 on 2022/3/31 15:29
 */
@Component
public class MySuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
    private RoleMapper roleMapper;
    @Autowired
    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.getWriter().write("success");
        //获取登录方法返回的对象
        BaseUser baseUser = (BaseUser) authentication.getPrincipal();
        //获取到用户的权限
        List<SysRole> roleList = roleMapper.findByUserId(baseUser.getUserId());
        Set<String> allPermisson = new HashSet<>();//用户所有的权限
        roleList.forEach(role -> {
        });
    }
}
